package enterprise.manage.web.controller.account;

import enterprise.manage.dao.UserDao;
import enterprise.manage.entity.User;
import enterprise.manage.security.utils.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController; 

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; 

/**
 * Created by IntelliJ IDEA.
 * User: liyong
 * Date: 2010-9-1
 * Time: 9:45:05
 * desc
 */
public class AccountIndexController extends AbstractController {

    /**
     * .
     * 日志
     */
    private static final Logger LOGGER = LoggerFactory.
            getLogger(AccountIndexController.class);

//    /**
//     * 超时返回页面
//     */
//    private static final String index = "redirect:/index.aspx";

    /**
     * 登录成功返回页面
     */
    private static final String INDEX_VIEW = "account/index";

    /**
     * 商户业务逻辑
     */
    @Autowired
    private UserDao userDao;

    @Override
    protected ModelAndView handleRequestInternal(
            HttpServletRequest request, HttpServletResponse response) throws Exception {

        LOGGER.info("进入查询用户信息控制器");

        String userName =  (String) request.getSession().getAttribute(SecurityUtils.SESSION_USER_NAME);

        if(userName == null) {
            return new ModelAndView("redirect:/index.aspx");
        }
//        Long userId = SecurityUtils.getUserId(request.getSession());
        LOGGER.info("账户名={}", userName);

        User user = userDao.getByUserName(userName);

        request.setAttribute("user", user);


        return new ModelAndView(INDEX_VIEW);
    }
}
